package com.lingyuting.orm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.commons.dbutils.DbUtils;

public class DbManager {

    public Connection getConnection() {
        String url = "jdbc:mysql://127.0.0.1:3306/test?characterEncoding=UTF-8";
        String jdbcDriver = "com.mysql.jdbc.Driver";
        String user = "root";
        String password = "root";
        DbUtils.loadDriver(jdbcDriver);
        Connection conn = null;
        try {
            return conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            e.printStackTrace();
            DbUtils.closeQuietly(conn);
            throw new RuntimeException(e);
        }
    }
}
